﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace BattleshipGameClient
{
    class ChatHistory
    {
        private SortedList<DateTime, ChatHistoryElement> elements = new SortedList<DateTime, ChatHistoryElement>();
        public void Add(DateTime timestamp, ChatHistoryElement element)
        {
            elements.Add(timestamp, element);
        }

        public string getRtf()
        {
            String returnValue = @"{\rtf1\ansi\deff0
{\colortbl;\red0\green0\blue0;\red50\green50\blue50;\red255\green0\blue0;\red0\green0\blue255;}";
            IList<DateTime> keys = elements.Keys;
            int color = 0;
            DateTime prev = new DateTime();
            foreach (DateTime key in keys)
            {
                if (elements[key].getMe())
                    color = 3;
                else
                    color = 4;

                if (key.Day != prev.Day)
                {

                    returnValue += @"
\cf2
" + key.ToString("f") + @"\line";
                }
                else if (key.Minute != prev.Minute)
                {

                    returnValue += @"
\cf2
" + key.ToString("t") + @"\line";
                }
                returnValue += @"
\cf" + color + @"
" + elements[key].getName() + @":
\cf1" + @"
 " + elements[key].getMessage() + @"\line";
                prev = key;
            }

            returnValue += @"
}";
            return returnValue;
        }
    }
}
